package com.bing.bingPro.controller.fiveOrder;

import com.bing.bingPro.ExcelUtil;
import com.bing.bingPro.common.BaseResult;
import com.bing.bingPro.controller.dto.TFiveOrderTypeDto;
import com.bing.bingPro.controller.vo.TCpOrderVo;
import com.bing.bingPro.controller.vo.TLstfOrderVo;
import com.bing.bingPro.service.TLstfOrderService;
import com.bing.bingPro.util.ExcelData;
import com.bing.bingPro.util.WebExcelUtil;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;


/**
 * 工单详表-低满工单详表(t_lstf_order)
 */
@RestController
public class TLstfOrderController {

    @Resource
    private TLstfOrderService tLstfOrderService;

    /**
     * 低满工单详表-列表
     *
     * @param tOrderYearDto
     * @return
     */
    @PostMapping("/lowFullnessList")
    public BaseResult<List<TLstfOrderVo>> lowFullnessList(@RequestBody TFiveOrderTypeDto tOrderYearDto) {
        return new BaseResult<>(this.tLstfOrderService.lowFullnessList(tOrderYearDto));
    }


    /**
     * 低满工单详表-导出
     *
     * @param response
     * @param tOrderYearDto
     * @throws Exception
     */
    @PostMapping("/exportLowFullness")
    public void exportLowFullness(HttpServletResponse response, @RequestBody TFiveOrderTypeDto tOrderYearDto) throws Exception {
        List<TLstfOrderVo> tLstfOrderVoList = tLstfOrderService.exportLowFullness(tOrderYearDto);
        //整理查询的数据
        List<ExcelData> excelDataList = new ArrayList<>();
        ExcelData excelData = new ExcelData(TLstfOrderVo.class,
                tLstfOrderVoList);
        excelDataList.add(excelData);
        //写出到浏览器
        WebExcelUtil.download(response, "低满工单详表" + tOrderYearDto.getTime(), excelDataList);
    }
}
